package com.biostime.dingdingbox.modules.db.api;


import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.biostime.dingdingbox.common.api.FastResponse;
import com.biostime.dingdingbox.common.api.ObjResponse;
import com.biostime.dingdingbox.common.web.BaseController;

import com.biostime.dingdingbox.modules.db.dto.GameStrategyDto;
import com.biostime.dingdingbox.modules.db.service.CommentService;
import com.biostime.dingdingbox.modules.db.service.GameStrategyService;
import com.biostime.dingdingbox.modules.db.service.MemberService;
import com.biostime.dingdingbox.modules.db.service.PraiseRecordService;


/**
 * 玩法攻略API
 * @author chenweicheng
 * @version 2016-06-28
 */
@RestController
@RequestMapping(value = "${adminPath}/db/api/strategy")
public class StrategyApi extends BaseController {
	
	@Autowired
	private PraiseRecordService praiseRecordService;
	
	@Autowired
	private GameStrategyService gameStrategyService;
	
	@Autowired
	private CommentService commentService;
	
	@Autowired
	private MemberService memberService;
	
	/**
	 * 玩法攻略详情
	 */
	@RequestMapping(value = "strategyDetail")
	public ObjResponse<GameStrategyDto> strategyDetail(String userId,String strategyId,HttpServletResponse response) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		userId = memberService.apiGetUserId(userId);
		GameStrategyDto strategy= new GameStrategyDto();
		if(userId != null && !userId.equals("")){
			strategy = gameStrategyService.apiGetStrategy(strategyId);
			if(strategy != null){
				strategy.setPraiseCount(praiseRecordService.apiRecomPraiseCount());
				if(praiseRecordService.apiStrategyPraiseCount(String.valueOf(strategy.getId()), userId) > 0){ 
					strategy.setIsPraised(1); 
				}						
				strategy.setCommentCount(commentService.apiGetCommentCount(String.valueOf(strategy.getId())));   				
			}
		}
		return  FastResponse.create().errMsg("获取玩法攻略详情成功").obj(strategy);		
	}	
	

}
